/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.qywx.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.qywx.entity.QiyePush;
import com.jeesite.modules.qywx.service.QiyePushService;

/**
 * 企业微信公众号维护管理Controller
 * @author SunXiaobing
 * @version 2019-08-13
 */
@Controller
@RequestMapping(value = "${adminPath}/qywx/qiyePush")
public class QiyePushController extends BaseController {

	@Autowired
	private QiyePushService qiyePushService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public QiyePush get(String id, boolean isNewRecord) {
		return qiyePushService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("qywx:qiyePush:view")
	@RequestMapping(value = {"list", ""})
	public String list(QiyePush qiyePush, Model model) {
		model.addAttribute("qiyePush", qiyePush);
		return "modules/qywx/qiyePushList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("qywx:qiyePush:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<QiyePush> listData(QiyePush qiyePush, HttpServletRequest request, HttpServletResponse response) {
		qiyePush.setPage(new Page<>(request, response));
		Page<QiyePush> page = qiyePushService.findPage(qiyePush);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("qywx:qiyePush:view")
	@RequestMapping(value = "form")
	public String form(QiyePush qiyePush, Model model) {
		model.addAttribute("qiyePush", qiyePush);
		return "modules/qywx/qiyePushForm";
	}

	/**
	 * 保存企业微信公众号维护管理
	 */
	@RequiresPermissions("qywx:qiyePush:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated QiyePush qiyePush) {
		qiyePushService.save(qiyePush);
		return renderResult(Global.TRUE, text("保存企业微信公众号维护管理成功！"));
	}
	
	/**
	 * 停用企业微信公众号维护管理
	 */
	@RequiresPermissions("qywx:qiyePush:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(QiyePush qiyePush) {
		qiyePush.setStatus(QiyePush.STATUS_DISABLE);
		qiyePushService.updateStatus(qiyePush);
		return renderResult(Global.TRUE, text("停用企业微信公众号维护管理成功"));
	}
	
	/**
	 * 启用企业微信公众号维护管理
	 */
	@RequiresPermissions("qywx:qiyePush:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(QiyePush qiyePush) {
		qiyePush.setStatus(QiyePush.STATUS_NORMAL);
		qiyePushService.updateStatus(qiyePush);
		return renderResult(Global.TRUE, text("启用企业微信公众号维护管理成功"));
	}
	
	/**
	 * 删除企业微信公众号维护管理
	 */
	@RequiresPermissions("qywx:qiyePush:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(QiyePush qiyePush) {
		qiyePushService.delete(qiyePush);
		return renderResult(Global.TRUE, text("删除企业微信公众号维护管理成功！"));
	}
	
}